/******************************************************************************* 
 * Copyright (c) 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation
 ******************************************************************************/
package net.sourceforge.perforce.internal.api;

import java.io.InputStream;

import net.sourceforge.perforce.core.api.ISubmitResult;
import net.sourceforge.perforce.core.internal.api.ChangeSpec;
import net.sourceforge.perforce.core.internal.api.Submit;

/**
  * @version $Revision: 119 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class SubmitTest extends ClientUserTestCase 
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Stores the ClientUser instance to test. */
	private Submit clientUser; 
	/** Stores the test progress monitor */
	private TestProgressMonitor monitor;
	
	// ------------------------------------------------------------------------- Public Constructors
	
	/** Constructor for SubmitTest.
	  *
	  * @param String name of the test. 
	  */
	public SubmitTest(String name)
	{
		super(name);
	}
	
	// ------------------------------------------------------------------------------ Public Methods
	
	/** Tests Submit with a valid result. */
	public void testValidResult()
		throws Exception
	{
		InputStream script = getClass().getResourceAsStream("submit_validResult.xml");
		executeScript(script, clientUser);
		
		assertTrue(clientUser.getStatus().isOK());
		
		ISubmitResult[] result = clientUser.getResult();
		assertEquals(3, result.length);

		assertEquals(
			"//p4eclipse/net.sourceforge.perforce.api/.project", 
			result[0].getDepotFilename());
		assertEquals("edit", result[0].getAction());
		assertTrue(result[0].isRefreshed());
		
		assertEquals(
			"//p4eclipse/net.sourceforge.perforce.api/build.properties", 
			result[1].getDepotFilename());
		assertEquals("delete", result[1].getAction());
		assertTrue(!result[1].isRefreshed());
		
		assertEquals(
			"//p4eclipse/net.sourceforge.perforce.api/jdbm.jar", 
			result[2].getDepotFilename());
		assertEquals("add", result[2].getAction());
		assertTrue(!result[2].isRefreshed());
		
		monitor.verify();
	}
	
	// --------------------------------------------------------------------------- Protected Mehtods
	
	/** @see net.sourceforge.perforce.internal.api.ClientUserTestCase#setUp() */
	protected void setUp() 
		throws Exception 
	{
		super.setUp();
		
		monitor = new TestProgressMonitor();
		
		ChangeSpec changeSpec = new ChangeSpec("specString", 3);
		clientUser = Submit.newInstanceForOutput(changeSpec, monitor);
	}
}
